var dateformat = function (time, format) {
    if (time.toString().length == 10) {
        var n = time * 1000;
    } else {
        var n = time
    }

    var date =new Date(n);
    var Y = date.getFullYear() + '-';
    var M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';
    var D = date.getDate() < 10 ? '0' + date.getDate() : date.getDate();
    var H = date.getHours() < 10 ? ' ' + '0' + date.getHours() + ':' : ' ' + date.getHours() + ':'; //時分秒与年月日有空格
    var I = date.getMinutes() < 10 ? '0' + date.getMinutes()  : date.getMinutes();
    var S = date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds();
    if (format == 'Y-M-D-H-I') {
        return (Y + M + D + H + I)
    } else if (format == 'H-I-S') {
        return (H + I + S)
    }  else if (format == 'Y-M') {
		var Y = date.getFullYear() + '-';
		var M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1);
        return (Y + M)
    }else if (format == '年-月-日') {I
        var Yfont = date.getFullYear() + '年';
        var Mfont = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '月';
        var Dfont = (date.getDate() < 10 ? '0' + date.getDate() : date.getDate()) + '日';
        return (Yfont + Mfont + Dfont)

    } 
    else {
        return (Y + M + D + H + I + S)
    }
}
module.exports = {
	dateformat
}